package main;

/**
 * 
 * @author Dylan
 * 
 * Controls the display of all objects in the game world. Independent from other parts
 * of the game, so it operates at its own frame rate. Currently handles the display
 * of all sprite objects, as long as they have been added to the sprites ArrayList in 
 * the model. Contained within a JPanel, so it can potentially be put into an applet or
 * full screen mode in the future. All code here should be written to support any window
 * size, as this number is set during initialization of the program.
 * 
 */

import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Collections;

import javax.swing.JPanel;

public class View extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Model model;
	
	public View(int width, int height, Model model) {
		super();
		
		this.model = model;
		
		Dimension window = new Dimension(width, height);
		this.setPreferredSize(window);
		this.setSize(window);
		this.setVisible(true);
	}

	@SuppressWarnings("unchecked")
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		Collections.sort(model.sprites);
		for (Sprite sprite : model.sprites){
			sprite.draw(g);
		}
	}
}
